

<include file="public@header" />
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('tameorder/goods')}">全部商品</a></li>
        <li><a href="{:url('tameorder/addgoods')}">添加商品</a></li>
    </ul>

    <table class="table table-hover table-bordered">

        <table class="layui-hide" id="test" lay-filter="test"></table>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">

            </div>
        </script>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>

        <!--    自定义    -->
        <script type="text/html" id="titleTpl">
            {{#  if(d.id < 2){ }}
            小于1
            {{#  } else { }}
            大于1
            {{#  } }}
        </script>


        <script>



            layui.use('table', function(){
                var table = layui.table;
                var curl="{:url('tameorder/goods')}";

                var tableIns =table.render({
                    elem: '#test' ,
                    url:curl,
                    method: 'post',
                    toolbar: '#toolbarDemo',
                    title: '数据表',
                    cols: [[
                        {field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                        ,{field:'name', title:'分类'}
                        ,{field:'goods', title:'产品'}
                        ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:180}
                    ]]
                    ,page: false
                });


                //表格工具行事件
                table.on('tool(test)', function(obj){
                    var data = obj.data;
                    //console.log(obj)
                    if(obj.event === 'del'){
                        layer.confirm('真的删除行么', function(index){
                            var curl="{:url('tameorder/deletegoods')}";
                            $.ajax({
                                url: curl,
                                data:{'id':data.id},
                                type:'post',
                                success:function (ret){
                                    obj.del();
                                    layer.close(index);
                                }
                            })




                            obj.del();
                            layer.close(index);
                        });
                    } else if(obj.event === 'edit'){
                        var curl="{:url('tameorder/editgoods')}?id="+data.id;

                        layer.open({
                            type: 2,
                            area: ['700px', '500px'],
                            content: curl,
                            success:function (){

                            },
                            end:function (){
                                location.reload();
                            }
                        });
                    }
                });


            });
        </script>


    </table>

</div>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>